package cn.cvs.servlet.sysRole;

import cn.cvs.pojo.SysRole;
import cn.cvs.service.SysRoleService;
import cn.cvs.util.SpringUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "UpdateRoleServlet", urlPatterns = "/sys/role/update")
public class UpdateRoleServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet ( request, response );
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding ( "utf-8" );
        response.setContentType ( "text/html;charset=UTF-8" );
        SysRoleService sysRoleService= (SysRoleService) SpringUtil.getBean ( "sysRoleService" );

        String id = request.getParameter ( "id" );
        String roleName = request.getParameter ( "roleName" );
        SysRole role=new SysRole ();
        role.setRoleName ( roleName );
        role.setId ( Integer.valueOf ( id ) );
        int update = sysRoleService.update ( role );
        if (update>0){
            request.getRequestDispatcher ( "/sys/role/list" ).forward ( request,response );
        }else {
            request.getRequestDispatcher ( "/sys/role/toUpdate" ).forward ( request,response );
        }
    }
}
